﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;


using EShop.Core.Model;
using EShop.Services.Store;

namespace EShop.App.Webs
{
    public class ProductController : Controller
    {
        #region Fields
        private readonly IDimensionService _dimensionService;
        private readonly IDimensionValueService _dimensionValueService;
        private readonly IProductService _productService;
        #endregion

        #region Constructors
        public ProductController(IDimensionService dimensionService, IDimensionValueService dimensionValueService, IProductService productService)
        {
            this._dimensionService = dimensionService;
            this._dimensionValueService = dimensionValueService;
            this._productService = productService;

        }
        #endregion

        public ActionResult Index(int? page, int? orderby, int? sort, int? selectSearch, string searchStr)
        {
            var dimension = _dimensionService.GetAllDimension();
            ViewBag.dimension = dimension;
            ViewBag.sort = sort == null ? 0 : sort;
            ViewBag.orderby = orderby == null ? 0 : orderby;
            string sortDirection = null;
            string sortField = null;
            if (sort == 2)
                sortDirection = "ASC";
            if (orderby == 4)
                sortField = "AddDate";
            else if (orderby == 5)
                sortField = "Price";
            if (page == null) page = 1;
            var list = _productService.GetAllProduct((int)page - 1, 20, sortDirection, sortField, selectSearch, searchStr);
            return View(list);

        }
    }
}
